// #include <stdio.h>

#define N_ELEM 5120000

int main ()
{
 int i;
  int n = N_ELEM;
  float pi, sum;
  // This could be run in the device 

 
#pragma llc context name("compute_pi") copy_out(pi, sum) copy_in(sum, n)
 {
  float h = 1.0 / (float) n;   // local var to the device
 /* createVar(regionId, &h, VAR_SCALAR) */

  /* S1*/ sum = 0.0f;   // Initial value to a global var

 /* A concyle statement is inserted by yacf
    concyle(&sum); 
 */

  /* S2*/ 
  #pragma llc for shared(h, n) reduction(+ : sum)
  for (i = 0; i <= n; i ++)
    {
      float x = h * ((float) i - 0.5);
      sum += 4.0 / (1.0 + x * x);
    }

 /* A concyle statement is inserted by yacf
    concyle(&sum); 
 */
  /* S3*/  pi = h * sum;
  }

 printf ("Pi %f \n", pi);


}
